Skip to content

Add uint128#21

Merged
Hrom131 merged 16 commits into
devfrom
feat/add-uint128
Jul 14, 2026
Merged

Add uint128#21
Hrom131 merged 16 commits into
devfrom
feat/add-uint128

Conversation

@aritkulova

Copy link
Copy Markdown
Collaborator

No description provided.

@aritkulova
aritkulova requested a review from Hrom131 July 7, 2026 21:47
@aritkulova aritkulova self-assigned this Jul 7, 2026
@LesterEvSe

Copy link
Copy Markdown
Collaborator

Okay, I see the problem with running the tests, they take a lot of time. I have been playing around with the code, and the main problem is that with match if_test_this_function(...) we run a lot of similar operations, and in fact, to reach, for example, assert_bool(is_zero_128(a), expected_bool);, we need to go through 10 checks beforehand.

For example, when I run code like this, simplex tests finishes in under 3s, compared to the current 45s:

fn main() {
    let fn_idx: u8 = witness::FUNCTION_INDEX;

    let a: u128 = witness::FIRST_ARG;
    let b: u128 = witness::SECOND_ARG;
    let expected: Option<u128> = witness::EXPECTED;

    let expected_bool: bool = witness::EXPECTED_BOOL;
    let second_expected: u128 = witness::SECOND_EXPECTED; // for cases where the result is a 256 bit value
    let third_expected: u128 = witness::THIRD_EXPECTED; // for cases where the result is 256 bit + 128 bit values

    match if_test_this_function(197, fn_idx) { true => { assert_bool(is_zero_128(a), expected_bool); }, false => (), };
}

Note: The same optimization is true for other operations as well. I checked this for fn_idx == 195.

I have two possible solutions:

Comment thread simf/lib/u128.simf
Comment thread simf/lib/u128.simf

@LesterEvSe LesterEvSe left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests for this optimization. Suggested cases: a_low == b_low, a_low - b_low == u64::MAX, and if possible a property test asserting q * b + r == a on randomized inputs

Comment thread simf/u128_test_bits.simf Outdated
Comment thread simf/u128_test_arithmetic.simf Outdated
Comment thread simf/lib/u128.simf
Comment thread simf/lib/u128.simf
Comment thread simf/lib/u128.simf
Comment thread simf/lib/u128.simf Outdated
Comment thread simf/lib/u128.simf Outdated
Comment thread simf/lib/u128.simf Outdated
Comment thread tests/u128_test_arithmetic.rs Outdated
Comment thread tests/u128_test_bits.rs Outdated
Comment thread tests/u128_test_bits.rs Outdated

@LesterEvSe LesterEvSe left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK b001da3; tested locally with simplex test --test-threads 10

@Hrom131 Hrom131 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Hrom131
Hrom131 merged commit 0e79bfd into dev Jul 14, 2026
1 check passed
@Hrom131
Hrom131 deleted the feat/add-uint128 branch July 14, 2026 15:05
Arvolear added a commit that referenced this pull request Jul 24, 2026
* Initial version (#8)

* added simplex template

* added assert functions with test

* documented functions in asserts file

* added todo comment

* updated simplex version to 0.0.5

* Example of a test with the unhappy path (#9)

* updated test with negative path for asserts

* fixed typo

* added helper function to mock;
fixed typo

* added more specific error check

* Updated smplx version (#12)

* updated minimal simplex version to 0.0.6

* fixed test command in ci

* Asserts function refactoring (#11)

* renamed asserts functions to be more consistent;
removed unsuported "pub" modifier

* made asserts test more detailed;
added random generation of test data

* added logical operations (#13)

* Added safe uint functions (#14)

* added safe functions for u8, u16, u32, u64

* added mocks and tests for uints

* fixed incorrect names in tests

* fixed import order in tests

* linting

* refactored error assertion in tests

* Updated readme (#15)

* updated readme

* added instructions for smplx installation

* Feat/modules (#17)

* updated contracts to use modules and imports

* updated u8, u16, u32 and u64 contracts to use modules and imports

* fixing ci by using smplx from specific commit

* trying to fix ci

* updated readme

* Refactor library architecture (#19)

* feat: recode `uint` operations for clarity

* feat: refactor `asserts_test.rs` and `README.md` a bit

* refactor: docstring a little bit more

* update: version of Simplex to `0.0.7`

* refactor: docstring for macros and simf code a bit

* Add uint128 (#21)

* added  functions for u128;
added assert_eq_128

* added test for assert_eq_128

* updated simplex version

* fixed typo

* fixed typo

* optimized mul_128;
removed temporary helper

* divided tests for uint128 to speed up github ci

* trying to optimize ci by running simplex tests on multiple threads

* removed unused witness

* refactored index in tests;
splitted test by module

* optimized u128

* added check for randomized inputs in tests

* added more test cases for sub128

* refactored and optimized tests

* added a fex test cases for div_mod_128

* refactored tests for left and right shift

* Add gt ge functions for uints (#23)

* added gt and ge operators

* removed  unnecessary pub modifier

* renamed assert_bool to prevent future collisions

* added gt and ge operators for u128

* Add functions for op_return (#22)

* added functions for op_return;
added run_with_op_return to helpers

* fixed todo

* added documentation for op_return functions

* Feat/get ready for release (#24)

* uodated readme

* updated Cargo.toml

* Helper functions for future confidential transactions on secp256k1 (#28)

* feat: add `u64_widen` helper function

* feat: add ec operations and test them, add asserts for u1

* refactor: delete unused file

* refactor(u64): restore gt and ge in u64_test.simf

* refactor: naming for elliptic curve operations

* refactor: rename u64_widen into u64_into_u256 and fix test case

* refactor: rename the test

* update: add secp256k1 operations to README file

* Fix/pre-release (#29)

* renamed logical_operations to boolean;
added xor

* linting

* added todo comment

* renamed boolean file to binary

* cleanup

---------

Co-authored-by: Yuliia Aritkulova <94910987+aritkulova@users.noreply.github.com>
Co-authored-by: Yevhenii Sekhin <evgenii.nikolaevichfgh@gmail.com>
Co-authored-by: Artem Chystiakov <artem.ch31@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants